% fname: routing_oddeven__sel_bufferlevel__topology_8x8__.m
% ./noxim -routing oddeven -sel bufferlevel -dimx 8 -dimy 8  -sim 10000 -warmup 2000 -size 8 8 -buffer 2 -hs 27 0.2 -hs 28 0.2 -hs 35 0.2 -hs 36 0.2 

function [max_pir, max_throughput, min_delay] = routing_oddeven__sel_bufferlevel__topology_8x8__(symbol)

data = [
%             pir      avg_delay     throughput      max_delay       rpackets         rflits
           0.0018        16.4413      0.0153208            100            920           7354
           0.0018        17.5681      0.0141947            212            866           6927
           0.0018        16.2225       0.015168             89            926           7402
           0.0018        16.1654      0.0147837            114            931           7451
           0.0018         16.167      0.0147621             71            916           7322
           0.0018        16.3073      0.0146593             94            908           7271
           0.0018        16.7855      0.0153422            106            937           7487
           0.0018        17.2749      0.0150333             87            902           7216
           0.0018        16.9311      0.0150041            109            914           7322
           0.0018        16.3121      0.0144286             79            910           7272
           0.0018         17.371      0.0158387             97            981           7856
           0.0018        16.0278      0.0141332             76            864           6897
           0.0018        16.2237      0.0155179            109            979           7821
           0.0018         15.735      0.0153021             87            917           7345
           0.0018         17.468      0.0153571            105            968           7740
           0.0018        17.1925      0.0143532            108            904           7234
           0.0018        17.4333      0.0154663            138            974           7795
           0.0018        17.9466      0.0158103            141            917           7336
           0.0018        16.8063      0.0157583             98            945           7564
           0.0018        17.6393      0.0148671            128            937           7493
            0.002         18.335      0.0167848            146           1024           8191
            0.002        21.6475      0.0162641            348           1010           8067
            0.002        16.7826      0.0159734            106            975           7795
            0.002        17.7515      0.0162177            112           1006           8044
            0.002        17.6728      0.0161055            112           1030           8246
            0.002        17.4103      0.0166089             98           1031           8238
            0.002        18.8299      0.0164012            127           1017           8135
            0.002        19.9681      0.0164087            135           1035           8270
            0.002        19.0496      0.0168648            132           1029           8230
            0.002        18.2802      0.0172056            156           1067           8534
            0.002        18.6886      0.0171721            139           1047           8380
            0.002        16.7559      0.0159119             68            971           7765
            0.002        18.2485      0.0158105            146           1014           8095
            0.002        20.6208      0.0177036            137           1097           8781
            0.002        19.2987      0.0166429            169           1048           8388
            0.002        18.7079      0.0164167            182           1034           8274
            0.002        19.4211      0.0171352            147           1045           8362
            0.002        18.6892      0.0167188            115           1004           8025
            0.002        16.9047      0.0152422            109            976           7804
            0.002        19.6918      0.0166996            154           1035           8283
           0.0022        19.4004      0.0169219            130           1084           8664
           0.0022        20.4228      0.0182324            183           1166           9335
           0.0022        20.0632      0.0184809            241           1091           8723
           0.0022        19.1918       0.018125            193           1142           9135
           0.0022        20.9956      0.0194831            181           1149           9196
           0.0022        18.6854      0.0172341            139           1084           8686
           0.0022        19.8464      0.0184127            135           1159           9280
           0.0022        20.5277      0.0180544            212           1120           8955
           0.0022         18.679      0.0180396            150           1084           8659
           0.0022        21.1173       0.017879            287           1108           8868
           0.0022        19.1412      0.0180565            137           1119           8956
           0.0022        19.0318      0.0166836            146           1068           8542
           0.0022        20.9046      0.0181587            166           1142           9152
           0.0022        20.5085      0.0188669            144           1170           9358
           0.0022        19.2504         0.0185            108           1166           9324
           0.0022         20.083      0.0176915            123           1097           8775
           0.0022         17.145       0.017418             81           1117           8918
           0.0022        18.9539      0.0174556            112           1084           8658
           0.0022        21.5822      0.0181548            152           1144           9150
           0.0022        18.9416      0.0179484            104           1131           9046
           0.0024        24.8833      0.0212172            200           1294          10354
           0.0024        23.1349       0.019916            146           1275          10197
           0.0024        22.1366      0.0189805            211           1215           9718
           0.0024        23.7759      0.0191468            318           1205           9650
           0.0024        22.3191      0.0196633            129           1219           9753
           0.0024        20.9992      0.0195933            186           1234           9875
           0.0024        21.3403      0.0198671            202           1252          10013
           0.0024        22.9823      0.0191573            161           1188           9502
           0.0024        19.9308      0.0182871            146           1170           9363
           0.0024        22.8258      0.0199961            187           1280          10238
           0.0024        21.3014      0.0190726            130           1181           9460
           0.0024        23.3281      0.0200377            233           1262          10099
           0.0024        25.1707      0.0192168            245           1230           9839
           0.0024        19.5998      0.0194713            176           1187           9502
           0.0024         21.109       0.018498            165           1184           9471
           0.0024        23.6462      0.0201211            319           1289          10302
           0.0024        19.7755      0.0186953            141           1198           9572
           0.0024        22.9146      0.0191992            141           1229           9830
           0.0024         23.358      0.0194194            181           1204           9632
           0.0024        21.2063      0.0193887            139           1241           9927
           0.0026        24.4472      0.0219444            185           1382          11060
           0.0026        23.3374      0.0204766            149           1310          10484
           0.0026        24.0223      0.0203105            292           1302          10399
           0.0026        28.4678      0.0208379            372           1334          10669
           0.0026        25.6787      0.0207793            149           1329          10639
           0.0026        31.2264      0.0212207            277           1356          10865
           0.0026        24.9056      0.0215323            412           1335          10680
           0.0026        24.8944      0.0216528            201           1364          10913
           0.0026        26.0366      0.0208965            253           1340          10699
           0.0026         28.848      0.0212798            370           1342          10725
           0.0026         23.958      0.0215337            149           1356          10853
           0.0026        25.9296      0.0216516            259           1321          10566
           0.0026        26.1287      0.0216508            190           1367          10912
           0.0026        25.4681      0.0216726            255           1365          10923
           0.0026        22.6109      0.0204277            164           1308          10459
           0.0026        23.6081      0.0208652            192           1337          10683
           0.0026        26.1148      0.0217656            220           1394          11144
           0.0026        26.9947      0.0208452            305           1314          10506
           0.0026          26.22      0.0210556            227           1327          10612
           0.0026        23.6921      0.0205215            235           1312          10507
           0.0028         36.185      0.0235664            531           1508          12066
           0.0028        29.1343      0.0226738            348           1452          11609
           0.0028        37.2001      0.0233869            579           1474          11787
           0.0028        26.0725      0.0221738            223           1420          11353
           0.0028         30.527       0.022873            329           1442          11528
           0.0028        28.7732      0.0220508            371           1411          11290
           0.0028        26.5606      0.0222698            269           1402          11224
           0.0028        26.6761      0.0220547            211           1411          11292
           0.0028        34.9764      0.0229048            375           1443          11544
           0.0028        38.4722      0.0227773            436           1457          11662
           0.0028        38.2245      0.0239214            614           1483          11865
           0.0028        29.3199      0.0224102            296           1435          11474
           0.0028         31.052      0.0228671            442           1441          11525
           0.0028        27.1564      0.0225898            233           1445          11566
           0.0028        28.5743      0.0228008            234           1461          11674
           0.0028        34.8102      0.0225918            817           1444          11567
           0.0028        35.3923      0.0228184            287           1463          11683
           0.0028        34.4228      0.0226309            602           1450          11587
           0.0028        32.9385       0.022877            425           1463          11713
           0.0028         25.733      0.0224687            197           1438          11504
            0.003        36.0846      0.0234453            321           1501          12004
            0.003        45.2064      0.0235391            552           1507          12052
            0.003        34.5957      0.0242266            464           1551          12404
            0.003        42.3042      0.0244648            452           1565          12526
            0.003        41.4763      0.0240833            544           1518          12138
            0.003        39.9623      0.0248613            304           1591          12729
            0.003         84.061      0.0241055           1414           1542          12342
            0.003        42.6396      0.0242832            600           1554          12433
            0.003        55.0713      0.0247539           1009           1585          12674
            0.003        41.6137      0.0241738            540           1548          12377
            0.003        35.5595      0.0246835            371           1530          12243
            0.003        55.8203      0.0249385            558           1569          12569
            0.003         66.325      0.0250098            796           1600          12805
            0.003        43.8677      0.0250488            635           1603          12825
            0.003        61.6123      0.0236582           1220           1514          12113
            0.003        37.6515      0.0241151            528           1521          12154
            0.003        39.4544      0.0234648            861           1503          12014
            0.003        35.7723      0.0243594            399           1559          12472
            0.003        38.5411      0.0243266            642           1508          12066
            0.003        39.4677      0.0238984            448           1531          12236
           0.0032        69.1249      0.0265694           1468           1674          13391
           0.0032        50.5608      0.0252871            761           1619          12947
           0.0032        40.0308      0.0248359            878           1591          12716
           0.0032        78.1906      0.0258867            997           1658          13254
           0.0032        137.294      0.0270879           2041           1733          13869
           0.0032        49.7405      0.0249844           1067           1599          12792
           0.0032        51.9156      0.0259199            935           1659          13271
           0.0032        47.6607      0.0251855            626           1612          12895
           0.0032        72.3159      0.0251387            950           1608          12871
           0.0032        64.8197      0.0255119           1477           1608          12858
           0.0032        46.2742      0.0253066            910           1619          12957
           0.0032         42.579      0.0248281            529           1589          12712
           0.0032        54.6778      0.0248379            755           1589          12717
           0.0032        64.4719      0.0264258           1137           1691          13530
           0.0032        58.9421      0.0250664            980           1605          12834
           0.0032        54.3043      0.0262361            779           1653          13223
           0.0032        50.9699      0.0264961            544           1695          13566
           0.0032        39.8383       0.025123            648           1608          12863
           0.0032        76.5009      0.0269961           1079           1729          13822
           0.0032        48.3555      0.0260547            903           1668          13340
           0.0034        72.1418      0.0265645           1468           1700          13601
           0.0034        82.9825      0.0277383           1083           1776          14202
           0.0034        81.4039       0.028207           1590           1805          14442
           0.0034        81.2697      0.0268398           1297           1717          13742
           0.0034        56.2808      0.0267976            907           1688          13506
           0.0034        54.5268      0.0268203            737           1716          13732
           0.0034        55.3093      0.0268929            603           1694          13554
           0.0034        124.262      0.0283516           2141           1815          14516
           0.0034        59.7562      0.0276953            925           1772          14180
           0.0034        67.7014      0.0257969           1052           1651          13208
           0.0034        108.448      0.0283789           1531           1816          14530
           0.0034        141.065      0.0279805           2930           1791          14326
           0.0034        109.458      0.0270273           1923           1731          13838
           0.0034        90.0312      0.0280508           1683           1796          14362
           0.0034        57.9494      0.0262559            749           1680          13443
           0.0034         104.64      0.0259067           1735           1632          13057
           0.0034        123.701      0.0272891           2051           1748          13972
           0.0034         148.72      0.0282222           2040           1778          14224
           0.0034        69.0394      0.0274121            953           1753          14035
           0.0034        85.2921      0.0271855           1227           1739          13919
           0.0036        164.257      0.0287207           3508           1838          14705
           0.0036        129.217      0.0282852           1629           1809          14482
           0.0036        240.798       0.028873           4142           1848          14783
           0.0036        127.223      0.0273848           2479           1751          14021
           0.0036        222.981      0.0292422           4441           1873          14972
           0.0036         120.65      0.0284004           3371           1818          14541
           0.0036        207.751      0.0292305           4217           1870          14966
           0.0036        107.671      0.0285039           1551           1825          14594
           0.0036        77.6139      0.0280625            828           1795          14368
           0.0036        213.444       0.029043           3060           1859          14870
           0.0036        116.128      0.0277969           1376           1779          14232
           0.0036        113.306      0.0282852           2312           1809          14482
           0.0036        269.097      0.0285293           4949           1827          14607
           0.0036        95.0378      0.0289414           1167           1852          14818
           0.0036        120.972      0.0288488           1827           1790          14309
           0.0036        184.916      0.0274902           2374           1761          14075
           0.0036        103.765      0.0281289           1825           1803          14402
           0.0036        131.917      0.0284648           3179           1821          14574
           0.0036        143.231      0.0278691           3532           1784          14269
           0.0036        149.876      0.0289648           1926           1852          14830
];

rows = size(data, 1);
cols = size(data, 2);

data_delay = [];
for i = 1:rows/20,
   ifirst = (i - 1) * 20 + 1;
   ilast  = ifirst + 20 - 1;
   tmp = data(ifirst:ilast, cols-5+1);
   avg = mean(tmp);
   [h sig ci] = ttest(tmp, 0.1);
   ci = (ci(2)-ci(1))/2;
   data_delay = [data_delay; data(ifirst, 1:cols-5), avg ci];
end

figure(1);
hold on;
plot(data_delay(:,1), data_delay(:,2), symbol);

data_throughput = [];
for i = 1:rows/20,
   ifirst = (i - 1) * 20 + 1;
   ilast  = ifirst + 20 - 1;
   tmp = data(ifirst:ilast, cols-5+2);
   avg = mean(tmp);
   [h sig ci] = ttest(tmp, 0.1);
   ci = (ci(2)-ci(1))/2;
   data_throughput = [data_throughput; data(ifirst, 1:cols-5), avg ci];
end

figure(2);
hold on;
plot(data_throughput(:,1), data_throughput(:,2), symbol);

data_maxdelay = [];
for i = 1:rows/20,
   ifirst = (i - 1) * 20 + 1;
   ilast  = ifirst + 20 - 1;
   tmp = data(ifirst:ilast, cols-5+3);
   avg = mean(tmp);
   [h sig ci] = ttest(tmp, 0.1);
   ci = (ci(2)-ci(1))/2;
   data_maxdelay = [data_maxdelay; data(ifirst, 1:cols-5), avg ci];
end

figure(3);
hold on;
plot(data_maxdelay(:,1), data_maxdelay(:,2), symbol);


%-------- Saturation Analysis -----------
slope=[];
for i=2:size(data_throughput,1),
    slope(i-1) = (data_throughput(i,2)-data_throughput(i-1,2))/(data_throughput(i,1)-data_throughput(i-1,1));
end

for i=2:size(slope,2),
    if slope(i) < (0.95*mean(slope(1:i)))
        max_pir = data_throughput(i, 1);
        max_throughput = data_throughput(i, 2);
        min_delay = data_delay(i, 2);
        break;
    end
end
